var express = require('express');
const { goodsList } = require('../data/home');
var data = require('../data/home/shopCart.js');
var Coe=require('../data/home/coe.js')
var Order=require('../data/home/order.js')
// var Orders=require('../data/home/order.js')
var router = express.Router();
//花束
router.get('/list/huashu', function (req, res, next) {
  res.send([
    {title:'花束',id:'1',name:'永恒回忆',price:'298',desc:'销量16022笔',picUrl:'http://127.0.0.1:3000/static/images/huashu/1.jpg'},
    {title:'花束',id:'2',name:'浪漫满屋',price:'229',desc:'销量15000笔',picUrl:'http://127.0.0.1:3000/static/images/huashu/2.jpg'},
    {title:'花束',id:'3',name:'相濡以沫',price:'229',desc:'销量12658笔',picUrl:'http://127.0.0.1:3000/static/images/huashu/3.jpg'},
    {title:'花束',id:'4',name:'此生不渝',price:'168',desc:'销量16256笔',picUrl:'http://127.0.0.1:3000/static/images/huashu/4.jpg'},
    {title:'花束',id:'5',name:'浪漫告白',price:'299',desc:'销量10368笔',picUrl:'http://127.0.0.1:3000/static/images/huashu/5.jpg'},
    {title:'花束',id:'6',name:'为你心动',price:'319',desc:'销量13141笔',picUrl:'http://127.0.0.1:3000/static/images/huashu/6.jpg'},
    {title:'花束',id:'7',name:'满天繁星',price:'299',desc:'销量15230笔',picUrl:'http://127.0.0.1:3000/static/images/huashu/7.jpg'},
    {title:'花束',id:'8',name:'不忘初心',price:'189',desc:'销量13568笔',picUrl:'http://127.0.0.1:3000/static/images/huashu/8.jpg'},
    {title:'花束',id:'9',name:'感恩的心',price:'239',desc:'销量12533笔',picUrl:'http://127.0.0.1:3000/static/images/huashu/9.jpg'},
    {title:'花束',id:'10',name:'温暖阳光',price:'269',desc:'销量11522笔',picUrl:'http://127.0.0.1:3000/static/images/huashu/10.jpg'},
  ])
})



//礼盒
router.get('/list/lihe', function (req, res, next) {
  res.send([
    {title:'礼盒',id:'11',name:'美丽的你',price:'239',desc:'销量9802笔',picUrl:'http://127.0.0.1:3000/static/images/lihe/1.jpg'},
    {title:'礼盒',id:'12',name:'缘分天空',price:'339',desc:'销量16200笔',picUrl:'http://127.0.0.1:3000/static/images/lihe/2.jpg'},
    {title:'礼盒',id:'13',name:'挚爱一生',price:'239',desc:'销量13622笔',picUrl:'http://127.0.0.1:3000/static/images/lihe/3.jpg'},
    {title:'礼盒',id:'14',name:'绵绵情谊',price:'239',desc:'销量11256笔',picUrl:'http://127.0.0.1:3000/static/images/lihe/4.jpg'},
    {title:'礼盒',id:'15',name:'为你守候',price:'199',desc:'销量8862笔',picUrl:'http://127.0.0.1:3000/static/images/lihe/5.jpg'},
    {title:'礼盒',id:'16',name:'情定一生',price:'319',desc:'销量11205笔',picUrl:'http://127.0.0.1:3000/static/images/lihe/6.jpg'},
    {title:'礼盒',id:'17',name:'岁月童话',price:'289',desc:'销量9999笔',picUrl:'http://127.0.0.1:3000/static/images/lihe/7.jpg'},
    {title:'礼盒',id:'18',name:'花好月圆',price:'189',desc:'销量5626笔',picUrl:'http://127.0.0.1:3000/static/images/lihe/8.jpg'},
  
   
  ])
})
//蛋糕
router.get('/list/dangao', function (req, res, next) {
  res.send([
    {title:'蛋糕',id:'19',name:'爱的火烈鸟',price:'239',desc:'销量5011笔',picUrl:'http://127.0.0.1:3000/static/images/dangao/1.jpg'},
    {title:'蛋糕',id:'20',name:'意气风发（8寸）',price:'359',desc:'销量3825笔',picUrl:'http://127.0.0.1:3000/static/images/dangao/2.jpg'},
    {title:'蛋糕',id:'21',name:'丝丝甜蜜（8寸）',price:'139',desc:'销量3399笔',picUrl:'http://127.0.0.1:3000/static/images/dangao/3.jpg'},
    {title:'蛋糕',id:'22',name:'幸福环绕',price:'239',desc:'销量3200笔',picUrl:'http://127.0.0.1:3000/static/images/dangao/4.jpg'},
    {title:'蛋糕',id:'23',name:'第一无二',price:'199',desc:'销量2941笔',picUrl:'http://127.0.0.1:3000/static/images/dangao/5.jpg'},
    {title:'蛋糕',id:'24',name:'快乐时光（10寸）',price:'319',desc:'销量2213笔',picUrl:'http://127.0.0.1:3000/static/images/dangao/6.jpg'},
    {title:'蛋糕',id:'25',name:'冰雪女王',price:'389',desc:'销量1765笔',picUrl:'http://127.0.0.1:3000/static/images/dangao/7.jpg'},
    {title:'蛋糕',id:'26',name:'你最珍贵',price:'189',desc:'销量3025笔',picUrl:'http://127.0.0.1:3000/static/images/dangao/8.jpg'},
  
   
  ])
})
// 花篮
router.get('/list/hualan', function (req, res, next) {
  res.send([
    {title:'花篮',id:'27',name:'旭日临门（一对）',price:'278',desc:'销量9802笔',picUrl:'http://127.0.0.1:3000/static/images/hualan/1.jpg'},
    {title:'花篮',id:'28',name:'喜气洋洋（一对）',price:'339',desc:'销量10235笔',picUrl:'http://127.0.0.1:3000/static/images/hualan/2.jpg'},
    {title:'花篮',id:'29',name:'招财进宝（一对）',price:'398',desc:'销量3622笔',picUrl:'http://127.0.0.1:3000/static/images/hualan/3.jpg'},
    {title:'花篮',id:'30',name:'好运连连（一对）',price:'298',desc:'销量7256笔',picUrl:'http://127.0.0.1:3000/static/images/hualan/4.jpg'},
    {title:'花篮',id:'31',name:'生意兴隆（一对）',price:'499',desc:'销量6862笔',picUrl:'http://127.0.0.1:3000/static/images/hualan/5.jpg'},
    {title:'花篮',id:'32',name:'前程似锦（一对）',price:'399',desc:'销量5205笔',picUrl:'http://127.0.0.1:3000/static/images/hualan/6.jpg'},
    {title:'花篮',id:'33',name:'大卖（一对）',price:'359',desc:'销量8999笔',picUrl:'http://127.0.0.1:3000/static/images/hualan/7.jpg'},
    {title:'花篮',id:'34',name:'开业大卖（一对）',price:'298',desc:'销量5626笔',picUrl:'http://127.0.0.1:3000/static/images/hualan/8.jpg'},
  
  ])
})
// 绿植
router.get('/list/lvzhi', function (req, res, next) {
  res.send([
    {title:'绿植',id:'35',name:'单柱发财盆栽1',price:'489',desc:'销量9802笔',picUrl:'http://127.0.0.1:3000/static/images/lvzhi/1.jpg'},
    {title:'绿植',id:'36',name:'单柱发财盆栽2',price:'489',desc:'销量7689笔',picUrl:'http://127.0.0.1:3000/static/images/lvzhi/2.jpg'},
    {title:'绿植',id:'37',name:'天堂鸟盆栽',price:'659',desc:'销量6158笔',picUrl:'http://127.0.0.1:3000/static/images/lvzhi/3.jpg'},
    {title:'绿植',id:'38',name:'万年青盆栽',price:'399',desc:'销量10228笔',picUrl:'http://127.0.0.1:3000/static/images/lvzhi/4.jpg'},
    {title:'绿植',id:'39',name:'百合竹盆栽',price:'399',desc:'销量5068笔',picUrl:'http://127.0.0.1:3000/static/images/lvzhi/5.jpg'},
    {title:'绿植',id:'40',name:'辫子发财盆栽',price:'519',desc:'销量7889笔',picUrl:'http://127.0.0.1:3000/static/images/lvzhi/6.jpg'},
    {title:'绿植',id:'41',name:'步步高升盆栽',price:'559',desc:'销量9232笔',picUrl:'http://127.0.0.1:3000/static/images/lvzhi/7.jpg'},
    {title:'绿植',id:'42',name:'落地大富盆栽',price:'438',desc:'销量5624笔',picUrl:'http://127.0.0.1:3000/static/images/lvzhi/8.jpg'},
  
   
  ])
})
// 花语
router.get('/list/huayu', function (req, res, next) {
  res.send([
    {
      id: '1', name: '郁金香',
      text: '爱的表白、荣誉，祝福，永恒',
      desc: '白色寓意纯洁的恋情、黄色寓意着开朗、紫色寓意着无尽的爱、粉色寓意着永远的爱、红色寓意爱意、喜悦。',
      picUrl: 'http://127.0.0.1:3000/static/images/huayu/1.jpg'
    },
    {
      id: '2', name: '百合',
      text: '清新脱俗的百合有如婀娜多姿的美丽佳人，不问尘事，只可远观而不可亵玩；顺利、心想事成、友情、祝福、高贵 、百年好合。',
      desc: '象征圣洁和吉祥，新娘手捧百合花，寓意百年好合，百事合意。百合花是一种姿态优美的草本花卉，每茎一花，状似喇叭，常有隐隐幽香',
      picUrl: 'http://127.0.0.1:3000/static/images/huayu/2.jpg'
    },
    {
      id: '3', name: '康乃馨',
      text: '康乃馨是所有女性的神圣之花，美好典雅的典范；母亲我爱您、热情、真情',
      desc: '大部分代表了爱，魅力和尊敬之情，红色代表了爱和关怀。粉红色康乃馨传说是圣母玛利亚看到耶稣受到苦难流下伤心的泪水，眼泪掉下的地方就长出来康乃馨，因此粉红康乃馨成为了不朽的母爱的象征。',
      picUrl: 'http://127.0.0.1:3000/static/images/huayu/3.jpg'
    },
    {
      id: '4', name: '蒲公英',
      text: '充满朝气的黄色花朵；开朗，属性风；停不了的爱，无法停留的爱，永不止息的爱',
      desc: '蒲公英的寓意大概就是随遇而安，蒲公英的每一粒种子都是跟随着风来播撒的，它们永远无法选择自己即将生长的土地，可能有的找到了肥活的土地，而有的则落在了贫瘠的土地，但是它们依然会选择适应环境然后扎根生长，这就是一种随遇而安的境界。',
      picUrl: 'http://127.0.0.1:3000/static/images/huayu/4.jpg'
    },
    {
      id: '5', name: '玫瑰',
      text: '爱情、爱与美、容光焕发、爱和艳情',
      desc: '玫瑰花在古希腊神话中，玫瑰集爱与美于一身，既是美神的化身，又溶进了爱神的血液。在世界范围内，玫瑰是用来表达爱情的通用语言。',
      picUrl: 'http://127.0.0.1:3000/static/images/huayu/5.jpg'
    },
    {
      id: '6', name: '牡丹',
      text: '喜欢牡丹的人以宽大的心胸和献身的爱情与人交往；圆满、浓情、富贵、雍容华贵',
      desc: '因其色、姿、香、韵俱佳，雍容华贵，庄重典雅，又被人们推崇为“花之富贵者”。同时，牡丹又被赋予了不畏强权的精神。',
      picUrl: 'http://127.0.0.1:3000/static/images/huayu/6.jpg'
    },



  ])
})
//remen
router.get('/list/remen', function (req, res, next) {
  res.send(
    [
      { id: '1', name: '永恒回忆', price: '298', desc: '销量16022笔', picUrl: 'http://127.0.0.1:3000/static/images/huashu/1.jpg' },
      { id: '12', name: '缘分天空', price: '339', desc: '销量16200笔', picUrl: 'http://127.0.0.1:3000/static/images/lihe/2.jpg' },
      { id: '13', name: '挚爱一生', price: '239', desc: '销量13622笔', picUrl: 'http://127.0.0.1:3000/static/images/lihe/3.jpg' },
      { id: '4', name: '此生不渝', price: '168', desc: '销量16256笔', picUrl: 'http://127.0.0.1:3000/static/images/huashu/4.jpg' },
      { id: '41', name: '步步高升盆栽', price: '559', desc: '销量9232笔', picUrl: 'http://127.0.0.1:3000/static/images/lvzhi/7.jpg' },
      { id: '42', name: '落地大富盆栽', price: '438', desc: '销量5624笔', picUrl: 'http://127.0.0.1:3000/static/images/lvzhi/8.jpg' },
      { id: '7', name: '满天繁星', price: '299', desc: '销量15230笔', picUrl: 'http://127.0.0.1:3000/static/images/huashu/7.jpg' },
      { id: '8', name: '不忘初心', price: '189', desc: '销量13568笔', picUrl: 'http://127.0.0.1:3000/static/images/huashu/8.jpg' },
      { id: '28', name: '喜气洋洋（一对）', price: '339', desc: '销量10235笔', picUrl: 'http://127.0.0.1:3000/static/images/hualan/2.jpg' },
      { id: '29', name: '招财进宝（一对）', price: '398', desc: '销量3622笔', picUrl: 'http://127.0.0.1:3000/static/images/hualan/3.jpg' },
    ]



  )
}
)

//商品详情
let {goodsLists} = require('../data/home/index.js')
router.get('/list/detail', function (req, res, next) {
  let index = goodsLists.findIndex(item => {
    return String(req.query.id) === String(item.id)
  })
 console.log(goodsLists[index]);
  if (index >= 0) {
    res.send(goodsLists[index])
  } else {
    res.send(false);
  }
})
//加入购物车
router.post('/addShopcart', function (req, res, next) {
  data.push(req.body)

  res.send(true)
})
//删除商品购物车
router.get('/delete', function (req, res, next) {
  // data.push(req.body)
  let index = data.findIndex(item => {
    return String(item.id) === String(req.query.id)
})
  data.splice(index, 1)

   res.send({
       msg: '删除成功',
       code: 200,
       data: true
   })
})
//结算删除购物车商品
router.post('/pay', function (req, res, next) {
  let payGoodes=req.body.payGoods
  payGoodes.forEach((item)=>{
    
    let indexDelete = data.findIndex(inItem => {
      return  Number(inItem.id) === Number(item.id)
    })
    if(indexDelete>=0){
      data.splice(indexDelete,1)
    }
  })
})
//加入我的收藏
router.post('/addCoe', function (req, res, next) {
  Coe.push(req.body)

  res.send(true)
})
//删除收藏物品
router.get('/Coedelete', function (req, res, next) {
  let index = Coe.findIndex(item => {
    return String(item.id) === String(req.query.id)
})
  Coe.splice(index, 1)

   res.send({
       msg: '删除成功',
       code: 200,
       data: true
   })
})
//同步至我的订单
router.post('/addOrder',function(req,res,next){
    // Order.push(req.body.addOrder)
    let order=req.body
    order.forEach((item,index)=>{
      Order.push(item)
    })
    // Order.push(req.body)
    res.send(true)
})
//删除订单
router.get('/Orderdelete',function(req,res,next){
  let orderDelete=Order.findIndex(item=>{
    return String(item.id)===String(req.query.id)
  })
  Order.splice(orderDelete,1)
  res.send({
    msg: '删除成功',
    code: 200,
    data: true
})
})
module.exports = router;
